{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Chapter 07\n",
    "# 四个for循环例子\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M\n",
      "a\n",
      "t\n",
      "p\n",
      "l\n",
      "o\n",
      "t\n",
      "l\n",
      "i\n",
      "b\n"
     ]
    }
   ],
   "source": [
    "# 循环字符串内字符\n",
    "str_for_loop = 'Matplotlib'\n",
    "for str_idx in str_for_loop:\n",
    "    print(str_idx)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:14:50.913683Z",
     "end_time": "2024-07-03T10:14:50.919861Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Matplotlib\n",
      "NumPy\n",
      "Seaborn\n",
      "Pandas\n",
      "Plotly\n",
      "SK-learn\n"
     ]
    }
   ],
   "source": [
    "# 循环list中元素\n",
    "list_for_loop = ['Matplotlib', 'NumPy', 'Seaborn',\n",
    "                 'Pandas', 'Plotly', 'SK-learn']\n",
    "for item_idx in list_for_loop:\n",
    "    print(item_idx)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:16:08.684415Z",
     "end_time": "2024-07-03T10:16:08.707782Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "=================\n",
      "Matplotlib\n",
      "A visualization tool\n",
      "=================\n",
      "NumPy\n",
      "=================\n",
      "Seaborn\n",
      "A visualization tool\n",
      "=================\n",
      "Pandas\n",
      "=================\n",
      "Plotly\n",
      "A visualization tool\n",
      "=================\n",
      "SK-learn\n"
     ]
    }
   ],
   "source": [
    "# 循环中嵌入 if 判断\n",
    "packages_visual = ['Matplotlib', 'Seaborn', 'Plotly']\n",
    "for item_idx in list_for_loop:\n",
    "    print('=================')\n",
    "    print(item_idx)\n",
    "    if item_idx in packages_visual:\n",
    "        print('A visualization tool')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:16:21.023772Z",
     "end_time": "2024-07-03T10:16:21.036994Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "===============\n",
      "Matplotlib\n",
      "M\n",
      "a\n",
      "t\n",
      "p\n",
      "l\n",
      "o\n",
      "t\n",
      "l\n",
      "i\n",
      "b\n",
      "===============\n",
      "NumPy\n",
      "N\n",
      "u\n",
      "m\n",
      "P\n",
      "y\n",
      "===============\n",
      "Seaborn\n",
      "S\n",
      "e\n",
      "a\n",
      "b\n",
      "o\n",
      "r\n",
      "n\n",
      "===============\n",
      "Pandas\n",
      "P\n",
      "a\n",
      "n\n",
      "d\n",
      "a\n",
      "s\n",
      "===============\n",
      "Plotly\n",
      "P\n",
      "l\n",
      "o\n",
      "t\n",
      "l\n",
      "y\n",
      "===============\n",
      "SK-learn\n",
      "S\n",
      "K\n",
      "-\n",
      "l\n",
      "e\n",
      "a\n",
      "r\n",
      "n\n"
     ]
    }
   ],
   "source": [
    "# 嵌套 for 循环\n",
    "for item_idx in list_for_loop:\n",
    "    print('===============')\n",
    "    print(item_idx)\n",
    "    for item_idx in item_idx:\n",
    "        print(item_idx)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-03T10:17:41.449271Z",
     "end_time": "2024-07-03T10:17:41.485079Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
